package com.waitingresult.log.aspectj;

import lombok.extern.slf4j.Slf4j;
import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
import org.aspectj.lang.reflect.MethodSignature;
import org.springframework.stereotype.Component;
import org.springframework.web.context.support.HttpRequestHandlerServlet;

import javax.servlet.http.HttpServletRequest;
import java.lang.reflect.Method;
import java.util.Enumeration;

/**
 * All right reserved,Designed By WangShuai
 *
 * @author : WangShuai
 * @version : V1.0
 * @ClassName : TLogAspect
 * @Description :
 * @date : 2021/9/9 10:52
 */
@Slf4j
@Aspect
@Component
public class TLogAspect {
    // 注入MQ 做异步处理
   /* @Autowired
    private RabbitService rabbitService;*/
    //TODO 异步处理没有做完,后续希望 写入到数据库中.

    /**
     * 声明切面,只要使用了这个注解的所有方法都会走到这里,配置织入点
     */
    @Pointcut("@annotation(com.waitingresult.log.annocation.TLog)")
    public void logPointcut() {
    }

    @Around("logPointcut()")
    public Object around(ProceedingJoinPoint point) throws Throwable {
        Class<?> clazz = point.getTarget().getClass();
        //获取方法名称
        String methodName = point.getSignature().getName();
        //参数类型
        Class<?>[] argsClass = ((MethodSignature) point.getSignature()).getParameterTypes();
        //请求方法
        Method method = clazz.getMethod(methodName, argsClass);


        return null;
    }

    protected void getHttpRequest(HttpServletRequest request){
        //Token值
        String token = request.getHeader("token");
    }

}
